<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>审核层</title>
		<link rel="stylesheet" href="res/layui/css/layui.css">
		<script src="res/js/jquery-2.1.4.min.js" type="text/javascript" ></script>
		<script src="res/layui/layui.js"></script>
	</head> 
	<body style="padding: 40px 40px 0px 40px">
		
		<form class="layui-form" id="shenhe">
			<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">备注</label>
			    <div class="layui-input-block">
			        <textarea placeholder="请输入内容" id="textarea" lay-verify="required" class="layui-textarea"></textarea>
			    </div>
			</div>
			<div class="layui-input-block">
		        <button class="layui-btn" lay-submit lay-filter="demo">通过</button>
		        <button class="layui-btn" lay-submit lay-filter="demo">打回</button>
		    </div>
		</form>
		
		<script type="text/javascript">
		
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引	
		var form;
		
		layui.use(['form'], function() {
			form = layui.form;
			//监听提交
			form.on('submit(demo)', function(data){
				var buttonText = $(data.elem).text();
				var url = "exam/sk.action";
				var data;
				if(buttonText == '通过'){
					if(GetQueryString("skType")==1){//如果是总店销售审核。
						data = {"examEntry":GetQueryString("entryId"),"state":"1","textarea":$("#textarea").val(),"fdProId":GetQueryString("fdProId"),"annexId":GetQueryString("annexId"),"skType":GetQueryString("skType")};
					}else if(GetQueryString("skType")==2){//总店采购审核
						data = {"examEntry":GetQueryString("entryId"),"state":"1","textarea":$("#textarea").val(),"skType":GetQueryString("skType"),"proType":GetQueryString("proType")};
					}else if(GetQueryString("skType")==3){//生产审核
						data = {"examEntry":GetQueryString("entryId"),"state":"1","textarea":$("#textarea").val(),"skType":GetQueryString("skType")};
					}else if(GetQueryString("skType")==4){//分店采购审核
						data = {"examEntry":GetQueryString("entryId"),"state":"1","textarea":$("#textarea").val(),"annexId":GetQueryString("annexId")}
					}
				}else{
					if(GetQueryString("skType")==1){//如果是总店销售审核。
						data = {"examEntry":GetQueryString("entryId"),"state":"3","textarea":$("#textarea").val(),"fdProId":GetQueryString("fdProId"),"annexId":GetQueryString("annexId"),"skType":GetQueryString("skType")};
					}else if(GetQueryString("skType")==2){//总店采购审核
						data = {"examEntry":GetQueryString("entryId"),"state":"3","textarea":$("#textarea").val(),"skType":GetQueryString("skType"),"proType":GetQueryString("proType")};
					}else if(GetQueryString("skType")==3){//生产审核
						data = {"examEntry":GetQueryString("entryId"),"state":"3","textarea":$("#textarea").val(),"skType":GetQueryString("skType")};
					}else if(GetQueryString("skType")==4){//分店采购审核
						data = {"examEntry":GetQueryString("entryId"),"state":"3","textarea":$("#textarea").val(),"annexId":GetQueryString("annexId")}
					}
				}
				//var loadIndex = layer.load();
				$.post(url, data, function(mes){
					//layer.close(loadIndex);//加载层关闭 
					if(mes==-1){
						layer.msg('库存不足，不能通过',{icon: 5,anim: 6});
					}else{
						parent.layer.close(index);
						$(".layui-laypage-skip .layui-laypage-btn",window.parent.document).click();//刷新父页面数据表格的当前页
					}
				});
				return false;
			});
		});
		
		/**
			得到URL栏的参数
		*/
		function GetQueryString(name){
		     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		     var r = window.location.search.substr(1).match(reg);
		     if(r!=null)return  unescape(r[2]); return null;
		}
		</script>
		
	</body>
</html>